
local currentTime = os.date("%Y-%m-%d %H:%M:%S", os.time())

currentTime = "\"" .. currentTime .. "\""

local req_body = '-'

if ngx.var.request_body then
     req_body = ngx.var.request_body
     req_body = string.gsub(req_body,"\n","")
     req_body = string.gsub(req_body,"\t","")
     req_body = string.gsub(req_body,"\"","'")
end

req_body = "\"" .. req_body .. "\""

local req_status = 0

if ngx.var.status then

     req_status = ngx.var.status

end

local req_time = 0

if ngx.var.request_time then

     req_time = ngx.var.request_time

end

local req_req = "\"" .. ngx.var.request .. "\""

--local remote_addr = "\"" .. ngx.var.http_x_forwarded_for .. "\""
local remote_addr = "\"gch\""
local server_addr = "\"" .. ngx.var.upstream_addr .. "\""

local myparams = ("("..remote_addr..",".. server_addr..","..currentTime..","..ngx.var.request_time .. ",".. ngx.var.upstream_response_time..","..ngx.var.body_bytes_sent..","..ngx.var.status..","..req_req..","..req_body..")")

local key = "logs"

local len,err = ngx.shared.logs:rpush(key, myparams)

--local jsonMessage = {}
--jsonMessage.remote_addr=remote_addr
--jsonMessage.server_addr=server_addr
--jsonMessage.currentTime=currentTime
--jsonMessage.request_time=ngx.var.request_time
--jsonMessage.upstream_response_time=ngx.var.upstream_response_time
--jsonMessage.rbody_bytes_sent=ngx.var.body_bytes_sent
--jsonMessage.status=ngx.var.status
--jsonMessage.req_req=ngx.var.req_req

--jsonMessage.req_body=ngx.var.req_body
--ngx.shared.logs:rpush("yunxin:order:List", cjson.encode(jsonMessage))

if err then

     ngx.log(ngx.ERR,"failed to put log vals into shared dict")

     return

end

